# -*- coding:utf-8 -*-
__author__   = 'tommy'
__license__  = 'htcharge.com@2016-08-29'
__version__  = 'v1.0.0'

import json, HTCUtils
import qwater,qcfg,qwaterdb


#订单详情的信息
def msgOrderMsg(aList):
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    tmpMsgRetsult["infos"]  = []

    i = i.split("&v;")
    tmpMsg                   = {}
    tmpMsg["saleno"]         = i[0]
    tmpMsg["posid"]          = i[1]
    tmpMsg["p_num"]          = i[2]
    tmpMsg["start_tones"]    = i[3]
    tmpMsg["tones"]          = i[4]
    tmpMsg["seconds"]        = i[5]
    tmpMsg["start_time"]     = i[6]
    tmpMsg["stop_time"]      = i[7]
    tmpMsg["p_second"]       = i[8]
    tmpMsg["p_tones"]        = i[9]
    tmpMsg["pay_type"]       = i[10]
    tmpMsg["username"]       = i[11]
    tmpMsg["stop_way"]       = i[12]
    tmpMsg["card"]           = i[13]
    tmpMsg["su_card"]        = i[14]
    tmpMsg["stop_tones"]     = i[15]
    tmpMsg["money"]          = i[16]
    tmpMsg["be_money"]       = i[17]
    tmpMsg["af_money"]       = i[18]
    tmpMsg["phone"]          = i[19]
    tmpMsg["card_type"]      = i[20]
    tmpMsg["d_name"]         = i[21]
    tmpMsg["mac"]            = i[22]
    tmpMsg["mincharge"]      = i[23]
    tmpMsg["market_name"]    = qcfg.MARK_NAME
    tmpMsg["url"]            = 'WWW.YLWOK.COM'
    tmpMsg["hotline"]        = '400-888-8888'
        
    tmpMsgRetsult["infos"].append(tmpMsg)
        
        
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)



#获取订单列表的信息
def msgOrderList(aList):
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    tmpMsgRetsult["infos"]  = []
    arr = aList.split("@@@")
    cishu = -1
    for i in arr :
        cishu = cishu + 1
        if (cishu == 0):
            continue;

        i = i.split("&v;")
        tmpMsg                   = {}
        tmpMsg["saleno"]         = i[1]
        tmpMsg["posid"]          = i[2]
        tmpMsg["p_num"]          = i[3]
        tmpMsg["start_tones"]    = i[4]
        tmpMsg["tones"]          = i[5]
        tmpMsg["seconds"]        = i[6]
        tmpMsg["start_time"]     = i[7]
        tmpMsg["stop_time"]      = i[8]
        tmpMsg["p_second"]       = i[9]
        tmpMsg["p_tones"]        = i[10]
        tmpMsg["pay_type"]       = i[11]
        tmpMsg["username"]       = i[12]
        tmpMsg["stop_way"]       = i[13]
        tmpMsg["card"]           = i[14]
        tmpMsg["su_card"]        = i[15]
        tmpMsg["stop_tones"]     = i[16]
        tmpMsg["money"]          = i[17]
        tmpMsg["be_money"]       = i[18]
        tmpMsg["af_money"]       = i[19]
        tmpMsg["phone"]          = i[20]
        tmpMsg["card_type"]      = i[21]
        tmpMsg["d_name"]         = i[22]
        tmpMsg["mac"]            = i[23]
        tmpMsg["mincharge"]      = i[24]
        tmpMsg["market_name"]    = qcfg.MARK_NAME
        tmpMsg["url"]            = 'WWW.YLWOK.COM'
        tmpMsg["hotline"]        = '400-888-8888'
        


        tmpMsgRetsult["infos"].append(tmpMsg)
        
        
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)

#获取单个设备的信息
def msgOneDev(aOneDev,aStatus,aVaule):

    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    tmpMsgRetsult["infos"]  = {}
    i = aOneDev.split("&v;")

    tmpMsg                  = {}
    tmpMsg["did"]           = i[0]
    tmpMsg["dname"]         = i[1]
    tmpMsg["mac"]           = i[2]
    tmpMsg["psecond"]       = i[3]
    tmpMsg["ptone"]         = i[4]
    tmpMsg["ptype"]         = i[5]
    tmpMsg["sdelay"]        = i[6]       #yanshi shijian
    tmpMsg["edelay"]        = i[7]       #yanshi shijian
    tmpMsg["mincharge"]     = i[8]
    tmpMsg["bala"]          = i[9]
    
    if (len(i) > 11):
        tmpMsg["saleno"]        = i[10]
        tmpMsg["umoney"]        = i[11]
        tmpMsg["stone"]         = i[12]
        tmpMsg["utone"]         = i[13]
        tmpMsg["utime"]         = i[14]
        tmpMsg["stime"]         = i[15]
        tmpMsg["etime"]         = i[16]
    
    if (aStatus == '0'):
        tmpMsg["dreading"]  = 0
        tmpMsg["dstatus"]   = 1
        tmpMsg["dustatus"]  = 0
    else:
        tmpMsg["dreading"]  = aVaule
        tmpMsg["dstatus"]   = 0
        tmpMsg["dustatus"]  = aStatus
    tmpMsg["marketname"]    = qcfg.MARK_NAME
    tmpMsgRetsult["infos"]  = tmpMsg
        
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)
    
    
# ,,根据经纬度 获取的列表
def msgLatLonList(aCard,aLonLatList):
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    tmpMsgRetsult["infos"]  = []
    #根据经纬度 获取的列表
    if (aLonLatList != -1):
        arr = aLonLatList.split("@@@")
        tmpDBmsnmacrecv = qwaterdb.dbSelectGetMsnMac(aCard,'0')
        cishu = -1
        for i in arr :
            cishu = cishu + 1
            if (cishu == 0):
                continue;
            i = i.split("&v;")
            tmpMsg                  = {}
            tmpMsg["dname"]         = i[1]
            tmpMsg["did"]           = i[2]
            tmpMsg["paytype"]       = i[3]
            tmpMsg["ptone"]         = i[4]
            tmpMsg["pseconde"]      = i[5]
            tmpMsg["mile"]          = i[6]
            tmpMsg["mac"]           = i[7]
            tmpMsg["sdelay"]        = i[8]       #yanshi shijian
            tmpMsg["edelay"]        = i[9]       #yanshi shijian
            
            tmpMsg["total"]         = 0.00
            tmpMsg["stime"]         = '0'
            tmpMsg["stone"]         = 0
            tmpMsg["utone"]         = 0
            tmpMsg["utime"]         = 0
            tmpMsg["deallimit"]     = 0
            #tmpMsg["card"]          = None
            #tmpMsg["username"]      = None
            
            if (tmpDBmsnmacrecv == -1):
                tmpMsg["dreading"]  = 0
                tmpMsg["dstatus"]   = 1
                tmpMsg["dustatus"]  = 0
            else:
                tmpMsn = tmpDBmsnmacrecv.split("&v;")[0]
                #tmpMac = tmpDBmsnmacrecv.split("&v;")[1]
                qwaserc = qwater.cmdStatus(tmpMsn,i[7])
                
                if (qwaserc == -1):
                    tmpMsg["dreading"]  = 0
                    tmpMsg["dstatus"]   = 1
                    tmpMsg["dustatus"]  = 0
                else:
                    dev_status = qwaserc.split("|")[0]
                    dev_value  = qwaserc.split("|")[1]
                    if (dev_status == '0'):
                        tmpMsg["dreading"]  = 0
                        tmpMsg["dstatus"]   = 1
                        tmpMsg["dustatus"]  = 0
                    else:
                        tmpMsg["dreading"]  = dev_value
                        tmpMsg["dstatus"]   = 0
                        tmpMsg["dustatus"]  = dev_status
            tmpMsgRetsult["infos"].append(tmpMsg)
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)
    
#使用列表的信息,
def msgUsingList(aCard,aUsingList):

    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    tmpMsgRetsult["infos"]  = []
    if (aUsingList == 0):
        HTCUtils.rctLogger.info(tmpMsgRetsult)
        return json.dumps(tmpMsgRetsult)
    if (aUsingList != -1):
        arr = aUsingList.split("@@@")
        cishu = -1
        for i in arr :
            cishu = cishu + 1
            if (cishu == 0):
                continue;

            i = i.split("&v;")
            tmpMsg                  = {}
            tmpMsg["did"]           = i[1]
            tmpMsg["paytype"]       = i[2]
            tmpMsg["ptone"]         = i[3]
            tmpMsg["pseconde"]      = i[4]
            tmpMsg["total"]         = i[5]
            tmpMsg["stime"]         = i[6]
            tmpMsg["stone"]         = i[7]
            tmpMsg["utone"]         = i[8]
            tmpMsg["utime"]         = i[9]
            tmpMsg["dname"]         = i[10]
            tmpMsg["deallimit"]     = i[11]
            tmpMsg["card"]          = i[12]
            tmpMsg["username"]      = i[13]
            tmpMsg["mac"]           = i[14]
            tmpMsg["sdelay"]        = i[15]       #yanshi shijian
            tmpMsg["edelay"]        = i[16]       #yanshi shijian
            qwaserc = qwater.cmdStatus(aCard,i[14])
            if (qwaserc == -1):
                tmpMsg["dreading"]  = 0
                tmpMsg["dstatus"]   = 1
                tmpMsg["dustatus"]  = 0
            else:
                dev_status = qwaserc.split("|")[0]
                dev_value  = qwaserc.split("|")[1]
                if (dev_status == '0'):
                    tmpMsg["dreading"]  = 0
                    tmpMsg["dstatus"]   = 1
                    tmpMsg["dustatus"]  = 0
                else:
                    tmpMsg["dreading"]  = dev_value
                    tmpMsg["dstatus"]   = 0
                    tmpMsg["dustatus"]  = dev_status

            tmpMsgRetsult["infos"].append(tmpMsg)
        
        
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)

#获取卡的信息
def msgCardInfos(aCardInfos):
    arr = aCardInfos.split("@@@")
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    tmpMsgRetsult["infos"]  = []
    for i in arr :
        i = i.split("&v;")
        tmpMsg                  = {}
        tmpMsg["card"]          = i[1]
        tmpMsg["suname"]        = i[2]
        tmpMsg["pn"]            = i[3]
        tmpMsg["inum"]          = i[4]
        tmpMsg["isex"]          = i[5]
        tmpMsg["ination"]       = i[6]
        tmpMsg["ibirth"]        = i[7]
        tmpMsg["iname"]         = i[8]
        tmpMsg["ctype"]         = i[9]
        tmpMsg["addr"]          = i[10]
        tmpMsg["coffi"]         = i[11]
        tmpMsg["cdealcount"]    = i[12]
        tmpMsg["cdeal"]         = i[13]
        tmpMsg["bala"]          = i[14]
        tmpMsg["stime"]         = i[15]
        tmpMsg["etime"]         = i[16]
        tmpMsgRetsult["infos"].append(tmpMsg)
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)

def msgError(aErr, aMsg):
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = int(aErr)
    tmpMsgRetsult["msg"] = HTCUtils.base64Encode(str(aMsg))
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)

def msgOk():
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    HTCUtils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)


